package com.softserveinc.autorent.manager;

import java.util.List;

import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.TypedQuery;

import com.softserveinc.autorent.model.CarPhoto;



@Stateless
public class CarPhotoEJB extends AbstractEJB<CarPhoto> {
	
	@PersistenceContext(unitName = "jpa")
	private EntityManager em;

	@Override
	public EntityManager getEntityManager() {
		return em;
	}

	@Override
	public void setEntityManager(EntityManager em) {
		this.em = em;
	}
	
	public CarPhotoEJB() {
		super(CarPhoto.class);
	}
/*@NamedQueries({
@NamedQuery(name = "CarPhoto.findAll", query = "SELECT f FROM CarPhoto f"),
@NamedQuery(name = "CarPhoto.findById", query = "SELECT f FROM CarPhoto f WHERE f.id = :id"),
@NamedQuery(name = "CarPhoto.findAllByCarModelId", query = "SELECT f FROM CarPhoto f WHERE f.carModel.id = :id")
})*/
	@Override
    public List<CarPhoto> findAll() {
        TypedQuery<CarPhoto> query = em.createNamedQuery("CarPhoto.findAll", CarPhoto.class);
        return query.getResultList();
    }
    public List<CarPhoto> findById(int id) {
        TypedQuery<CarPhoto> query = em.createNamedQuery("CarPhoto.findById", CarPhoto.class);
        query.setParameter("id", id);
        return query.getResultList();
    }
    public List<CarPhoto> findAllByCarModelId(int id) {
        TypedQuery<CarPhoto> query = em.createNamedQuery("CarPhoto.findAllByCarModelId", CarPhoto.class);
        query.setParameter("id", id);        
        return query.getResultList();
    }

    

}
